package appapi.service.impl;

import appapi.dao.TerminalMapper;
import appapi.entity.Zhongjiao.StaffDto;
import appapi.entity.mqtt.Terminal;
import appapi.entity.mqtt.TerminalReq;
import appapi.entity.mqtt.Terminals;
import appapi.service.TerminalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version: java version 1.8
 * @Author: Ygp Work
 * @description:
 * @date: 2023-07-04 10:58
 */
@Service
public class TerminalServceImpl extends ServiceImpl<TerminalMapper, Terminal> implements TerminalService {
    @Autowired
    TerminalMapper terminalMapper;

    @Override
    public int addTerminal(Terminal terminal) {
        return terminalMapper.insertTerminal(terminal);
    }

    @Override
    public int deleteTerminalById(String termId) {
    return terminalMapper.deleteTerminalById(termId);
    }

    @Override
    public int updateTerminal(Terminal terminal) {
    return terminalMapper.updateTerminal(terminal);
    }

    @Override
    public List<Terminal> getTerminalById(TerminalReq req) {
        return terminalMapper.getTerminalByOnAndTopics(req.getTermNo(),req.getTermTopic());
    }

    @Override
    public Terminal getTerminalByIds(String termNo, String termTopic) {
        return terminalMapper.getTerminalByOnAndTopic(termNo,termTopic);
    }

    @Override
    public PageInfo<Terminals> getTerminalAll(Terminals terminal) {
        if (ObjectUtils.allNotNull(terminal.getCurrPage(), terminal.getPageSize())) {
            PageHelper.startPage(terminal.getCurrPage(), terminal.getPageSize());
        }
        List<Terminals> terminalAll = terminalMapper.getTerminalAlls(terminal);
        PageInfo pageInfo = new PageInfo(terminalAll);
        return pageInfo;
    }

    @Override
    public List<Terminal> getTerminalAlls(Terminal terminal) {
        return terminalMapper.getTerminalAll(terminal);
    }

    @Override
    public List<StaffDto> getUserall() {
        return terminalMapper.getUserAll();
    }
}
